// Table 1. Summary statistics

use "eseefirmlevel.dta", clear

cap file close fh
file open fh using table1.txt, write replace
file write fh _n "Category" _tab "Before" _tab "After" _tab "Change" _tab "Change in perc"
foreach var in   adv inv_it rd inv_veh   inv_mach   inv_fur   {
cap drop `var'_mn
gen `var'_mn=`var'/1000000
}
foreach var in  adv_mn inv_it_mn rd_mn inv_veh_mn   inv_mach_mn   inv_fur_mn  creditratio crcost  {
sum `var' if crisis==0
local output=round(r(mean), 0.01)
file write fh _n "`var'" _tab (`output') 
sum `var' if crisis==1
local output2=round(r(mean), 0.01)
file write fh _tab (`output2') 
local diff=`output2'-`output'
file write fh _tab (`diff')
ttest `var', by(crisis) unequal unpaired
if r(p)<0.1 {
file write fh "*"
} 
if r(p)<0.05 {
file write fh "*"
}
if r(p)<0.01 {
file write fh "*"
}
local diffperc=round((`output2'-`output')/`output'*100,0.1)
file write fh _tab (`diffperc')
if r(p)<0.1 {
file write fh "*"
} 
if r(p)<0.05 {
file write fh "*"
}
if r(p)<0.01 {
file write fh "*"
}
ci `var' if crisis==0
local output=round(r(se), 0.01)
file write fh _n "" _tab "("
file write fh (`output')
file write fh ")"
ci `var' if crisis==1
local output=round(r(se), 0.01)
file write fh "" _tab "("
file write fh (`output')
file write fh ")"  _tab ""
}
file close fh
